<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.2.0">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">



<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.15.1/css/all.min.css">

<script class="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"yuanzhiying.github.io","root":"/","images":"/images","scheme":"Gemini","version":"8.1.0","exturl":false,"sidebar":{"position":"right","display":"post","padding":18,"offset":12},"copycode":true,"bookmark":{"enable":true,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"motion":{"enable":false,"async":false,"transition":{"post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"prism":false,"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"},"path":"/search.xml","localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false}};
  </script>
<meta name="description" content="Container添加 padding, margins, borders, background color, 或将其他装饰添加到widget Scaffold使用Scaffold是最容易的，它是 Material Components库中的一个widget，它提供了一个默认banner，背景颜色，并且具有添加drawer，snack bar和底部sheet的API DefaultTextSt">
<meta property="og:type" content="article">
<meta property="og:title" content="Flutter、Dart学习总结">
<meta property="og:url" content="http://yuanzhiying.github.io/2020/12/08/Flutter%E3%80%81Dart%E5%AD%A6%E4%B9%A0%E6%80%BB%E7%BB%93/index.html">
<meta property="og:site_name" content="yuanzhiying的博客">
<meta property="og:description" content="Container添加 padding, margins, borders, background color, 或将其他装饰添加到widget Scaffold使用Scaffold是最容易的，它是 Material Components库中的一个widget，它提供了一个默认banner，背景颜色，并且具有添加drawer，snack bar和底部sheet的API DefaultTextSt">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="http://yuanzhiying.github.io/2020/12/08/Flutter%E3%80%81Dart%E5%AD%A6%E4%B9%A0%E6%80%BB%E7%BB%93/2988687-b38ed2f78df0bcec.png">
<meta property="article:published_time" content="2020-12-08T07:37:16.000Z">
<meta property="article:modified_time" content="2021-01-26T05:52:41.207Z">
<meta property="article:author" content="yuanzhiying">
<meta property="article:tag" content="Flutter">
<meta property="article:tag" content="Dart">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http://yuanzhiying.github.io/2020/12/08/Flutter%E3%80%81Dart%E5%AD%A6%E4%B9%A0%E6%80%BB%E7%BB%93/2988687-b38ed2f78df0bcec.png">


<link rel="canonical" href="http://yuanzhiying.github.io/2020/12/08/Flutter%E3%80%81Dart%E5%AD%A6%E4%B9%A0%E6%80%BB%E7%BB%93/">


<script data-pjax class="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>
<title>Flutter、Dart学习总结 | yuanzhiying的博客</title>
  



  <noscript>
  <style>
  body { margin-top: 2rem; }

  .use-motion .menu-item,
  .use-motion .sidebar,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header {
    visibility: visible;
  }

  .use-motion .header,
  .use-motion .site-brand-container .toggle,
  .use-motion .footer { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle,
  .use-motion .custom-logo-image {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line {
    transform: scaleX(1);
  }

  .search-pop-overlay, .sidebar-nav { display: none; }
  .sidebar-panel { display: block; }
  </style>
</noscript>

<link rel="alternate" href="/atom.xml" title="yuanzhiying的博客" type="application/atom+xml">
</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="headband"></div>

  <main class="main">
    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <i class="logo-line"></i>
      <h1 class="site-title">yuanzhiying的博客</h1>
      <i class="logo-line"></i>
    </a>
      <p class="site-subtitle" itemprop="description">工作学习记录</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu">
        <li class="menu-item menu-item-home"><a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a></li>
        <li class="menu-item menu-item-categories"><a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类<span class="badge">4</span></a></li>
        <li class="menu-item menu-item-tags"><a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签<span class="badge">7</span></a></li>
        <li class="menu-item menu-item-archives"><a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档<span class="badge">9</span></a></li>
        <li class="menu-item menu-item-about"><a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于</a></li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup"><div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off" maxlength="80"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div class="search-result-container no-result">
  <div class="search-result-icon">
    <i class="fa fa-spinner fa-pulse fa-5x"></i>
  </div>
</div>

    </div>
  </div>

</div>
        
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
  </div>

  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <section class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-4"><a class="nav-link" href="#Container"><span class="nav-number">1.</span> <span class="nav-text">Container</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#Scaffold"><span class="nav-number">2.</span> <span class="nav-text">Scaffold</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#DefaultTextStyle"><span class="nav-number">3.</span> <span class="nav-text">DefaultTextStyle</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#maxCrossAxisExtent"><span class="nav-number">4.</span> <span class="nav-text">maxCrossAxisExtent</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#SizedBox"><span class="nav-number">5.</span> <span class="nav-text">SizedBox</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#State%E7%8A%B6%E6%80%81%E7%AE%A1%E7%90%86"><span class="nav-number">6.</span> <span class="nav-text">State状态管理</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#flutter%E7%9A%84Key"><span class="nav-number">7.</span> <span class="nav-text">flutter的Key</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#flutter%E7%9A%84json%E8%BD%AC%E4%B8%BA%E5%AE%9E%E4%BD%93%E7%B1%BB%E6%8F%92%E4%BB%B6%EF%BC%88Android-Studio%E6%8F%92%E4%BB%B6%EF%BC%89"><span class="nav-number">8.</span> <span class="nav-text">flutter的json转为实体类插件（Android Studio插件）</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#dart%E4%B8%ADexport%E4%BD%BF%E7%94%A8"><span class="nav-number">9.</span> <span class="nav-text">dart中export使用</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#cupertino%E4%B8%8Bpush%E7%9A%84%E5%90%8C%E6%97%B6%EF%BC%8C%E9%9A%90%E8%97%8Ftabbar"><span class="nav-number">10.</span> <span class="nav-text">cupertino下push的同时，隐藏tabbar</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#flutter%E4%BD%BF%E7%94%A816%E8%BF%9B%E5%88%B6%E8%89%B2%E5%80%BC"><span class="nav-number">11.</span> <span class="nav-text">flutter使用16进制色值</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#flutter%E8%8E%B7%E5%8F%96%E5%B1%8F%E5%B9%95%E5%AE%BD%E9%AB%98%E5%92%8C%E7%8A%B6%E6%80%81%E6%A0%8F%E9%AB%98%E5%BA%A6"><span class="nav-number">12.</span> <span class="nav-text">flutter获取屏幕宽高和状态栏高度</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#GestureDetector%E4%B8%BA%E5%B8%83%E5%B1%80%E6%B7%BB%E5%8A%A0%E6%89%8B%E5%8A%BF%EF%BC%8Cchild%E5%92%8C%E7%A9%BA%E7%99%BD%E5%8C%BA%E5%9F%9F%E5%85%A8%E9%83%A8%E5%8F%AF%E7%82%B9%E5%87%BB"><span class="nav-number">13.</span> <span class="nav-text">GestureDetector为布局添加手势，child和空白区域全部可点击</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E9%9A%90%E8%97%8F%E9%94%AE%E7%9B%98"><span class="nav-number">14.</span> <span class="nav-text">隐藏键盘</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#dynamic%E7%9A%84%E4%BD%BF%E7%94%A8"><span class="nav-number">15.</span> <span class="nav-text">dynamic的使用</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#flutter%E5%BB%B6%E8%BF%9F%E6%89%A7%E8%A1%8C"><span class="nav-number">16.</span> <span class="nav-text">flutter延迟执行</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#flutter%E4%B8%ADurl%E4%B8%AD%E7%BC%96%E7%A0%81%E8%A7%A3%E7%A0%81"><span class="nav-number">17.</span> <span class="nav-text">flutter中url中编码解码</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#flutter%E7%9A%84%E5%9B%BE%E7%89%87%E5%B8%83%E5%B1%80%E5%A1%AB%E5%85%85%E6%BB%A1%E7%88%B6%E5%B8%83%E5%B1%80"><span class="nav-number">18.</span> <span class="nav-text">flutter的图片布局填充满父布局</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#Text%E8%B6%85%E5%87%BA%E7%9C%81%E7%95%A5%E5%8F%B7%E6%88%AA%E6%96%AD"><span class="nav-number">19.</span> <span class="nav-text">Text超出省略号截断</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#list%E9%80%9A%E8%BF%87map%E8%BD%AC%E5%8C%96%E7%9A%84%E6%97%B6%E5%80%99%E8%8E%B7%E5%8F%96index"><span class="nav-number">20.</span> <span class="nav-text">list通过map转化的时候获取index</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#Cookie%E7%AE%A1%E7%90%86"><span class="nav-number">21.</span> <span class="nav-text">Cookie管理</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#Appbar%E4%B8%AD%E4%BD%BF%E7%94%A8%E8%87%AA%E5%AE%9A%E4%B9%89%E7%9A%84%E8%BF%94%E5%9B%9E%E6%8C%89%E9%92%AE"><span class="nav-number">22.</span> <span class="nav-text">Appbar中使用自定义的返回按钮</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E8%AE%BE%E7%BD%AEappbar%E9%AB%98%E5%BA%A6"><span class="nav-number">23.</span> <span class="nav-text">设置appbar高度</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E4%BD%BF%E7%94%A8webview-flutter%E6%97%B6%E6%89%A7%E8%A1%8C%E8%B0%83%E7%94%A8js%E7%9A%84%E6%96%B9%E6%B3%95%EF%BC%9A"><span class="nav-number">24.</span> <span class="nav-text">使用webview_flutter时执行调用js的方法：</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#android-studio%E4%B8%AD%E4%BD%BF%E7%94%A8print%E6%89%93%E5%8D%B0%EF%BC%8C%E5%8F%AA%E8%83%BD%E6%89%93%E5%8D%B0%E5%87%BA%E4%B8%80%E9%83%A8%E5%88%86%E7%9A%84%E8%A7%A3%E5%86%B3%E5%8A%9E%E6%B3%95%EF%BC%9A"><span class="nav-number">25.</span> <span class="nav-text">android studio中使用print打印，只能打印出一部分的解决办法：</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#TabBar%E5%AF%B9%E5%BA%94%E7%9A%84TabController%E4%BD%BF%E7%94%A8%E4%BB%A3%E7%A0%81%E5%88%87%E6%8D%A2tabBar-index%E4%BB%8E0%E5%BC%80%E5%A7%8B-%EF%BC%9A"><span class="nav-number">26.</span> <span class="nav-text">TabBar对应的TabController使用代码切换tabBar (index从0开始)：</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#flutter%E5%AF%8C%E6%96%87%E6%9C%ACRichText%E4%BD%BF%E7%94%A8"><span class="nav-number">27.</span> <span class="nav-text">flutter富文本RichText使用</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E5%A4%8D%E5%88%B6%E5%88%B0%E7%B2%98%E8%B4%B4%E6%9D%BF"><span class="nav-number">28.</span> <span class="nav-text">复制到粘贴板</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E8%BF%94%E5%9B%9E%E5%BD%93%E5%89%8D%E7%9A%84%E6%97%B6%E9%97%B4%E6%88%B3"><span class="nav-number">29.</span> <span class="nav-text">返回当前的时间戳</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E8%BF%94%E5%9B%9E%E6%96%87%E4%BB%B6%E5%A4%A7%E5%B0%8F%E5%AD%97%E7%AC%A6%E4%B8%B2"><span class="nav-number">30.</span> <span class="nav-text">返回文件大小字符串</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#flutter%E8%B0%83%E8%B5%B7%E6%8B%A8%E6%89%93%E7%94%B5%E8%AF%9D"><span class="nav-number">31.</span> <span class="nav-text">flutter调起拨打电话</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E5%9E%82%E7%9B%B4%E5%88%86%E5%89%B2%E7%BA%BF"><span class="nav-number">32.</span> <span class="nav-text">垂直分割线</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E5%8F%AF%E5%8F%96%E6%B6%88%E7%9A%84%E5%AE%9A%E6%97%B6%E4%BB%BB%E5%8A%A1"><span class="nav-number">33.</span> <span class="nav-text">可取消的定时任务</span></a></li></ol></div>
        </section>
        <!--/noindex-->

        <section class="site-overview-wrap sidebar-panel">
          <div class="site-author site-overview-item animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">yuanzhiying</p>
  <div class="site-description" itemprop="description">坚持下去</div>
</div>
<div class="site-state-wrap site-overview-item animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">9</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">4</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">7</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author site-overview-item animated">
      <span class="links-of-author-item">
        <a href="https://github.com/yuanzhiying" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;yuanzhiying" rel="noopener" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
  </div>



        </section>
      </div>
        <div class="back-to-top animated">
          <i class="fa fa-arrow-up"></i>
          <span>0%</span>
        </div>
    </div>
  </aside>
  <div class="sidebar-dimmer"></div>


    </header>

    
  <div class="reading-progress-bar"></div>
  <a role="button" class="book-mark-link book-mark-link-fixed"></a>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


    <div class="main-inner post posts-expand">


  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://yuanzhiying.github.io/2020/12/08/Flutter%E3%80%81Dart%E5%AD%A6%E4%B9%A0%E6%80%BB%E7%BB%93/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="yuanzhiying">
      <meta itemprop="description" content="坚持下去">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="yuanzhiying的博客">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          Flutter、Dart学习总结
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2020-12-08 15:37:16" itemprop="dateCreated datePublished" datetime="2020-12-08T15:37:16+08:00">2020-12-08</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">更新于</span>
        <time title="修改时间：2021-01-26 13:52:41" itemprop="dateModified" datetime="2021-01-26T13:52:41+08:00">2021-01-26</time>
      </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/Flutter/" itemprop="url" rel="index"><span itemprop="name">Flutter</span></a>
        </span>
    </span>

  
    <span class="post-meta-item" title="阅读次数" id="busuanzi_container_page_pv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="far fa-eye"></i>
      </span>
      <span class="post-meta-item-text">阅读次数：</span>
      <span id="busuanzi_value_page_pv"></span>
    </span>
      </div>
      <div class="post-meta">
    <span class="post-meta-item" title="本文字数">
      <span class="post-meta-item-icon">
        <i class="far fa-file-word"></i>
      </span>
      <span class="post-meta-item-text">本文字数：</span>
      <span>6.5k</span>
    </span>
    <span class="post-meta-item" title="阅读时长">
      <span class="post-meta-item-icon">
        <i class="far fa-clock"></i>
      </span>
      <span class="post-meta-item-text">阅读时长 &asymp;</span>
      <span>6 分钟</span>
    </span>
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
        <ul>
<li><h4 id="Container"><a href="#Container" class="headerlink" title="Container"></a>Container</h4>添加 padding, margins, borders, background color, 或将其他装饰添加到widget</li>
<li><h4 id="Scaffold"><a href="#Scaffold" class="headerlink" title="Scaffold"></a>Scaffold</h4>使用Scaffold是最容易的，它是 Material Components库中的一个widget，它提供了一个默认banner，背景颜色，并且具有添加drawer，snack bar和底部sheet的API</li>
<li><h4 id="DefaultTextStyle"><a href="#DefaultTextStyle" class="headerlink" title="DefaultTextStyle"></a>DefaultTextStyle</h4>DefaultTextStyle.merge可以允许您创建一个默认的文本样式，该样式会被其所有的子节点继承</li>
<li><h4 id="maxCrossAxisExtent"><a href="#maxCrossAxisExtent" class="headerlink" title="maxCrossAxisExtent"></a>maxCrossAxisExtent</h4><a target="_blank" rel="noopener" href="https://www.jianshu.com/p/8a142e06c48e">GridView.extent中maxCrossAxisExtent的作用</a></li>
<li><h4 id="SizedBox"><a href="#SizedBox" class="headerlink" title="SizedBox"></a>SizedBox</h4>能强制子控件具有特定宽度、高度或两者都有,使子控件设置的宽高失效<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">new SizedBox(</span><br><span class="line">  width: 100.0,</span><br><span class="line">  height: 100.0,</span><br><span class="line">  child: Container(</span><br><span class="line">    width: 200.0,</span><br><span class="line">    height: 200.0,</span><br><span class="line">    color: Color(0xffff0000),</span><br><span class="line">  ),</span><br><span class="line">)</span><br></pre></td></tr></table></figure></li>
<li><h4 id="State状态管理"><a href="#State状态管理" class="headerlink" title="State状态管理"></a>State状态管理</h4></li>
</ul>
<ol>
<li>如果状态是用户数据，如复选框的选中状态、滑块的位置，则该状态最好由父widget管理</li>
<li>如果所讨论的状态是有关界面外观效果的，例如动画，那么状态最好由widget本身来管理</li>
<li>如果有疑问，首选是在父widget中管理状态</li>
</ol>
<ul>
<li><h4 id="flutter的Key"><a href="#flutter的Key" class="headerlink" title="flutter的Key"></a>flutter的Key</h4><a target="_blank" rel="noopener" href="https://www.jianshu.com/p/fc88c0774078">Flutter–&gt;何时需要使用到key？</a><br><a target="_blank" rel="noopener" href="https://www.jianshu.com/p/3b2bc9f0ddd6">flutter 中的 key</a></li>
<li><h4 id="flutter的json转为实体类插件（Android-Studio插件）"><a href="#flutter的json转为实体类插件（Android-Studio插件）" class="headerlink" title="flutter的json转为实体类插件（Android Studio插件）"></a>flutter的json转为实体类插件（Android Studio插件）</h4>AS中搜索插件<code>FlutterJsonBeanFactory </code>，安装，重启AS。<br>在指定目录下，右键，new - dart bean class File From JSON，粘贴进json，格式化，生成即可。<br><img src="/2020/12/08/Flutter%E3%80%81Dart%E5%AD%A6%E4%B9%A0%E6%80%BB%E7%BB%93/2988687-b38ed2f78df0bcec.png" alt="2988687-b38ed2f78df0bcec.png"></li>
<li><h4 id="dart中export使用"><a href="#dart中export使用" class="headerlink" title="dart中export使用"></a>dart中export使用</h4>在A库中使用export关键字引入B库，当我们使用A库的时候，会自动引入B库，也就是说我们导入了A库，就可以使用B库了。</li>
<li><h4 id="cupertino下push的同时，隐藏tabbar"><a href="#cupertino下push的同时，隐藏tabbar" class="headerlink" title="cupertino下push的同时，隐藏tabbar"></a>cupertino下push的同时，隐藏tabbar</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">Navigator.of(context, rootNavigator: true)</span><br><span class="line">          .push(CupertinoPageRoute(builder: (BuildContext context) &#123;</span><br><span class="line">        return new MsgCenterPage();</span><br><span class="line">      &#125;));</span><br></pre></td></tr></table></figure></li>
<li><h4 id="flutter使用16进制色值"><a href="#flutter使用16进制色值" class="headerlink" title="flutter使用16进制色值"></a>flutter使用16进制色值</h4>Color(0xFFFF8A65)其中0x后面的两位FF表示透明度16进制，FF后面为色值</li>
<li><h4 id="flutter获取屏幕宽高和状态栏高度"><a href="#flutter获取屏幕宽高和状态栏高度" class="headerlink" title="flutter获取屏幕宽高和状态栏高度"></a>flutter获取屏幕宽高和状态栏高度</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;** 获取屏幕宽度 *&#x2F;</span><br><span class="line">  static double getScreenWidth(BuildContext context) &#123;</span><br><span class="line">    return MediaQuery.of(context).size.width;</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  &#x2F;** 获取屏幕高度 *&#x2F;</span><br><span class="line">  static double getScreenHeight(BuildContext context) &#123;</span><br><span class="line">    return MediaQuery.of(context).size.height;</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  &#x2F;** 获取系统状态栏高度 *&#x2F;</span><br><span class="line">  static double getSysStatsHeight(BuildContext context) &#123;</span><br><span class="line">    return MediaQuery.of(context).padding.top;</span><br><span class="line">  &#125;</span><br></pre></td></tr></table></figure></li>
<li><h4 id="GestureDetector为布局添加手势，child和空白区域全部可点击"><a href="#GestureDetector为布局添加手势，child和空白区域全部可点击" class="headerlink" title="GestureDetector为布局添加手势，child和空白区域全部可点击"></a>GestureDetector为布局添加手势，child和空白区域全部可点击</h4>GestureDetector的child添加为Container，同时Container要设置color，整体Container的child和空白区域才全部可点击，否则则是Container的child可点而空白不可点击。</li>
<li><h4 id="隐藏键盘"><a href="#隐藏键盘" class="headerlink" title="隐藏键盘"></a>隐藏键盘</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">FocusScope.of(context).requestFocus(FocusNode());</span><br></pre></td></tr></table></figure></li>
<li><h4 id="dynamic的使用"><a href="#dynamic的使用" class="headerlink" title="dynamic的使用"></a>dynamic的使用</h4>在数据解析过程中，如果不确定当前类型的话，可以使用dynamic来代替，具体是某个类型的话，再转为某个类型。<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">@JsonSerializable()</span><br><span class="line">class ResultData extends Object &#123;</span><br><span class="line"></span><br><span class="line">  @JsonKey(name: &#39;code&#39;)</span><br><span class="line">  String code;</span><br><span class="line"></span><br><span class="line">  @JsonKey(name: &#39;data&#39;)</span><br><span class="line">  dynamic data;</span><br><span class="line"></span><br><span class="line">  @JsonKey(name: &#39;url&#39;)</span><br><span class="line">  String url;</span><br><span class="line"></span><br><span class="line">  @JsonKey(name: &#39;message&#39;)</span><br><span class="line">  String message;</span><br><span class="line"></span><br><span class="line">  ResultData(this.code,this.data,this.url,this.message,);</span><br><span class="line"></span><br><span class="line">  factory ResultData.fromJson(Map&lt;String, dynamic&gt; srcJson) &#x3D;&gt; _$ResultDataFromJson(srcJson);</span><br><span class="line"></span><br><span class="line">  Map&lt;String, dynamic&gt; toJson() &#x3D;&gt; _$ResultDataToJson(this);</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></li>
<li><h4 id="flutter延迟执行"><a href="#flutter延迟执行" class="headerlink" title="flutter延迟执行"></a>flutter延迟执行</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">new Future.delayed(Duration(seconds: 2), () &#123;</span><br><span class="line">        Navigator.of(context).pop();</span><br><span class="line">      &#125;);</span><br></pre></td></tr></table></figure></li>
<li><h4 id="flutter中url中编码解码"><a href="#flutter中url中编码解码" class="headerlink" title="flutter中url中编码解码"></a>flutter中url中编码解码</h4>例如：需要将<br><code>js://iOSAction?%7B%22method%22:%22toLogin%22%7D</code><br>转为<br><code>js://iOSAction?&#123;&quot;method&quot;:&quot;toLogin&quot;&#125;</code><br>使用Uri的decode方法：<br><code>String url = Uri.decodeFull(navigation.url);</code><br>相反，编码的话，使用Uri的encode方法。</li>
<li><h4 id="flutter的图片布局填充满父布局"><a href="#flutter的图片布局填充满父布局" class="headerlink" title="flutter的图片布局填充满父布局"></a>flutter的图片布局填充满父布局</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">方法一：</span><br><span class="line">new ConstrainedBox(</span><br><span class="line">                  constraints: new BoxConstraints.expand(),</span><br><span class="line">                  child: new FadeInImage.assetNetwork(</span><br><span class="line">                    placeholder: &quot;assets&#x2F;home&#x2F;placeholder_default.png&quot;,</span><br><span class="line">                    image: model !&#x3D; null</span><br><span class="line">                        ? &quot;$&#123;APIConfig.pictureURL&#125;&quot;</span><br><span class="line">                        &quot;$&#123;model.pictureUrl&#125;&quot;</span><br><span class="line">                        : null,</span><br><span class="line">                    fit: BoxFit.fill,</span><br><span class="line">                  ),</span><br><span class="line">                ),</span><br><span class="line"></span><br><span class="line">方法二：</span><br><span class="line">如果已知宽高，Image里直接定义指定的宽和高</span><br><span class="line">MediaQuery.of(context).size.width</span><br><span class="line">MediaQuery.of(context).size.height</span><br></pre></td></tr></table></figure></li>
<li><h4 id="Text超出省略号截断"><a href="#Text超出省略号截断" class="headerlink" title="Text超出省略号截断"></a>Text超出省略号截断</h4><code>TextOverflow.ellipsis</code><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">new Text(</span><br><span class="line">                  &#39;我爱北京天安门，我爱北京天安门，我爱北京天安门，我爱北京天安门，我爱北京天安门，我爱北京天安门，我爱北京天安门&#39;,</span><br><span class="line">                  overflow: TextOverflow.ellipsis,</span><br><span class="line">                ),</span><br></pre></td></tr></table></figure></li>
<li><h4 id="list通过map转化的时候获取index"><a href="#list通过map转化的时候获取index" class="headerlink" title="list通过map转化的时候获取index"></a><code>list</code>通过<code>map</code>转化的时候获取<code>index</code></h4><code>list</code>通过<code>asMap</code>转为<code>Map</code>，然后使用<code>Map.map</code>获取<code>index</code>。<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line">homeNoticeList</span><br><span class="line">    .asMap()</span><br><span class="line">    .map((index, model) &#x3D;&gt; MapEntry(</span><br><span class="line">          index,</span><br><span class="line">          new GestureDetector(</span><br><span class="line">            onTap: () &#123;</span><br><span class="line">              logPrint(index, message: &quot;我点击了滚动的广告&quot;);</span><br><span class="line">            &#125;,</span><br><span class="line">            child: new Container(</span><br><span class="line">              color: ColorConfig.white,</span><br><span class="line">              child: new Align(</span><br><span class="line">                alignment: Alignment.centerLeft,</span><br><span class="line">                child: new Text(</span><br><span class="line">                  model.title,</span><br><span class="line">                  style: new TextStyle(fontSize: 14.0),</span><br><span class="line">                  overflow: TextOverflow.ellipsis,</span><br><span class="line">                ),</span><br><span class="line">              ),</span><br><span class="line">            ),</span><br><span class="line">          ),</span><br><span class="line">        ))</span><br><span class="line">    .values</span><br><span class="line">    .toList();</span><br></pre></td></tr></table></figure></li>
<li><h4 id="Cookie管理"><a href="#Cookie管理" class="headerlink" title="Cookie管理"></a><code>Cookie</code>管理</h4>网络请求使用dio进行网络请求，可以添加cookiemanager拦截器，来对cookie进行自动管理，也可手动删除cookie。<br>Flutter中添加依赖<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">dio: ^2.1.7 # 网络请求</span><br><span class="line">cookie_jar: ^1.0.0 # cookie管理</span><br></pre></td></tr></table></figure>
dio请求封装中，添加拦截器：<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;&#x2F; 添加&#96;Cookie&#96;管理</span><br><span class="line">    dio.interceptors.add(CookieManager(CookieJar()));</span><br></pre></td></tr></table></figure>
然后在<code>request</code>的<code>headers</code>中会自动增加<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">cookie: SESSION&#x3D;9d41c3e9-5619-492f-aa92-d85add6b04ed</span><br></pre></td></tr></table></figure>
与<code>iOS</code>的<code>moya</code> <code>cookie</code>不一样，一个是<code>cookie</code>，一个是<code>&quot;Set-Cookie&quot;</code>（header中拼入）：<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">[&quot;Set-Cookie&quot;:SESSION&#x3D;9d41c3e9-5619-492f-aa92-d85add6b04ed]</span><br></pre></td></tr></table></figure></li>
<li><h4 id="Appbar中使用自定义的返回按钮"><a href="#Appbar中使用自定义的返回按钮" class="headerlink" title="Appbar中使用自定义的返回按钮"></a><code>Appbar</code>中使用自定义的返回按钮</h4>先设置<code>automaticallyImplyLeading</code>为<code>false</code>，然后在<code>leading</code>中设置返回按钮。<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">automaticallyImplyLeading: false,</span><br><span class="line">        leading: new GestureDetector(</span><br><span class="line">          onTap: () &#123;</span><br><span class="line">            Navigator.of(context).pop();</span><br><span class="line">          &#125;,</span><br><span class="line">          child: new Image.asset(&#39;assets&#x2F;common&#x2F;nav_back_arrow.png&#39;),</span><br><span class="line">        ),</span><br></pre></td></tr></table></figure></li>
<li><h4 id="设置appbar高度"><a href="#设置appbar高度" class="headerlink" title="设置appbar高度"></a>设置appbar高度</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">appBar: new PreferredSize(</span><br><span class="line">        child: appBar,</span><br><span class="line">        preferredSize: Size.fromHeight(44),</span><br><span class="line">      ),</span><br></pre></td></tr></table></figure></li>
<li><h4 id="使用webview-flutter时执行调用js的方法："><a href="#使用webview-flutter时执行调用js的方法：" class="headerlink" title="使用webview_flutter时执行调用js的方法："></a>使用<code>webview_flutter</code>时执行调用<code>js</code>的方法：</h4>推荐在<code>onPageFinished</code>里调用。<br>例如：<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">onPageFinished: (String url) &#123;</span><br><span class="line">                      print(&quot;page finished loading: $url&quot;);</span><br><span class="line">                      setState(() &#123;</span><br><span class="line">                        isLoading &#x3D; false;</span><br><span class="line">                      &#125;);</span><br><span class="line"></span><br><span class="line">                      &#x2F;&#x2F; 如果为项目风险等级的url，则执行隐藏header的js。</span><br><span class="line">                      if (widget.url &#x3D;&#x3D; ContentConfig.projectRiskLevel) &#123;</span><br><span class="line">                        _controller.future.then((controller) &#123;</span><br><span class="line">                          controller</span><br><span class="line">                              .evaluateJavascript(&#39;hideHeader();&#39;)</span><br><span class="line">                              .then((result) &#123;&#125;);</span><br><span class="line">                        &#125;);</span><br><span class="line">                      &#125;</span><br><span class="line">                    &#125;</span><br></pre></td></tr></table></figure></li>
<li><h4 id="android-studio中使用print打印，只能打印出一部分的解决办法："><a href="#android-studio中使用print打印，只能打印出一部分的解决办法：" class="headerlink" title="android studio中使用print打印，只能打印出一部分的解决办法："></a><code>android studio</code>中使用<code>print</code>打印，只能打印出一部分的解决办法：</h4>导入<code>foundation</code>库：<br><code>import &#39;package:flutter/foundation.dart&#39;;</code><br>使用<code>flutter</code>里<code>foundation</code>中的<code>debugPrint</code>打印即可打印全部。</li>
<li><h4 id="TabBar对应的TabController使用代码切换tabBar-index从0开始-："><a href="#TabBar对应的TabController使用代码切换tabBar-index从0开始-：" class="headerlink" title="TabBar对应的TabController使用代码切换tabBar (index从0开始)："></a>TabBar对应的TabController使用代码切换tabBar (index从0开始)：</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">controller.animateTo(index);</span><br></pre></td></tr></table></figure></li>
<li><h4 id="flutter富文本RichText使用"><a href="#flutter富文本RichText使用" class="headerlink" title="flutter富文本RichText使用"></a>flutter富文本RichText使用</h4><a target="_blank" rel="noopener" href="https://www.jianshu.com/p/c4ee2a7a97d2">RichText在段落中显示不同样式</a></li>
<li><h4 id="复制到粘贴板"><a href="#复制到粘贴板" class="headerlink" title="复制到粘贴板"></a>复制到粘贴板</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">import &#39;package:flutter&#x2F;services.dart&#39;;</span><br><span class="line"></span><br><span class="line">  static copyToClipboard(final String text) &#123;</span><br><span class="line">    if (text &#x3D;&#x3D; null) return;</span><br><span class="line">    Clipboard.setData(new ClipboardData(text: text));</span><br><span class="line">  &#125;</span><br></pre></td></tr></table></figure></li>
<li><h4 id="返回当前的时间戳"><a href="#返回当前的时间戳" class="headerlink" title="返回当前的时间戳"></a>返回当前的时间戳</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">static int currentTimeMillis() &#123;</span><br><span class="line">    return new DateTime.now().millisecondsSinceEpoch;</span><br><span class="line">  &#125;</span><br></pre></td></tr></table></figure></li>
<li><h4 id="返回文件大小字符串"><a href="#返回文件大小字符串" class="headerlink" title="返回文件大小字符串"></a>返回文件大小字符串</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line">static const RollupSize_Units &#x3D; [&quot;GB&quot;, &quot;MB&quot;, &quot;KB&quot;, &quot;B&quot;];</span><br><span class="line">  &#x2F;** 返回文件大小字符串 *&#x2F;</span><br><span class="line">  static String getRollupSize(int size) &#123;</span><br><span class="line">    int idx &#x3D; 3;</span><br><span class="line">    int r1 &#x3D; 0;</span><br><span class="line">    String result &#x3D; &quot;&quot;;</span><br><span class="line">    while (idx &gt;&#x3D; 0) &#123;</span><br><span class="line">      int s1 &#x3D; size % 1024;</span><br><span class="line">      size &#x3D; size &gt;&gt; 10;</span><br><span class="line">      if (size &#x3D;&#x3D; 0 || idx &#x3D;&#x3D; 0) &#123;</span><br><span class="line">        r1 &#x3D; (r1 * 100) ~&#x2F; 1024;</span><br><span class="line">        if (r1 &gt; 0) &#123;</span><br><span class="line">          if (r1 &gt;&#x3D; 10)</span><br><span class="line">            result &#x3D; &quot;$s1.$r1$&#123;RollupSize_Units[idx]&#125;&quot;;</span><br><span class="line">          else</span><br><span class="line">            result &#x3D; &quot;$s1.0$r1$&#123;RollupSize_Units[idx]&#125;&quot;;</span><br><span class="line">        &#125; else</span><br><span class="line">          result &#x3D; s1.toString() + RollupSize_Units[idx];</span><br><span class="line">        break;</span><br><span class="line">      &#125;</span><br><span class="line">      r1 &#x3D; s1;</span><br><span class="line">      idx--;</span><br><span class="line">    &#125;</span><br><span class="line">    return result;</span><br><span class="line">  &#125;</span><br></pre></td></tr></table></figure></li>
<li><h4 id="flutter调起拨打电话"><a href="#flutter调起拨打电话" class="headerlink" title="flutter调起拨打电话"></a>flutter调起拨打电话</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">import &#39;package:url_launcher&#x2F;url_launcher.dart&#39;;</span><br><span class="line"></span><br><span class="line">Future&lt;void&gt; _launched;</span><br><span class="line"></span><br><span class="line">Future&lt;void&gt; _makePhoneCall(String url) async &#123;</span><br><span class="line">    if (await canLaunch(url)) &#123;</span><br><span class="line">      await launch(url);</span><br><span class="line">    &#125; else &#123;</span><br><span class="line">      throw &#39;Could not launch $url&#39;;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">&#x2F;&#x2F; 调起拨打电话</span><br><span class="line">          setState(() &#123;</span><br><span class="line">            _launched &#x3D; _makePhoneCall(&#39;tel:18612345678&#39;);</span><br><span class="line">          &#125;);</span><br></pre></td></tr></table></figure></li>
<li><h4 id="垂直分割线"><a href="#垂直分割线" class="headerlink" title="垂直分割线"></a>垂直分割线</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">Container(</span><br><span class="line">                  height: 40,</span><br><span class="line">                  child: VerticalDivider(color: Colors.red),</span><br><span class="line">                ),</span><br></pre></td></tr></table></figure></li>
<li><h4 id="可取消的定时任务"><a href="#可取消的定时任务" class="headerlink" title="可取消的定时任务"></a>可取消的定时任务</h4>Timer代替Future.</li>
</ul>

    </div>

    
    
    
      


    <footer class="post-footer">
          

<div class="post-copyright">
<ul>
  <li class="post-copyright-author">
      <strong>本文作者： </strong>yuanzhiying
  </li>
  <li class="post-copyright-link">
      <strong>本文链接：</strong>
      <a href="http://yuanzhiying.github.io/2020/12/08/Flutter%E3%80%81Dart%E5%AD%A6%E4%B9%A0%E6%80%BB%E7%BB%93/" title="Flutter、Dart学习总结">http://yuanzhiying.github.io/2020/12/08/Flutter、Dart学习总结/</a>
  </li>
  <li class="post-copyright-license">
    <strong>版权声明： </strong>本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" rel="noopener" target="_blank"><i class="fab fa-fw fa-creative-commons"></i>BY-NC-SA</a> 许可协议。转载请注明出处！
  </li>
</ul>
</div>

          <div class="post-tags">
              <a href="/tags/Flutter/" rel="tag"><i class="fa fa-tag"></i> Flutter</a>
              <a href="/tags/Dart/" rel="tag"><i class="fa fa-tag"></i> Dart</a>
          </div>

        

          <div class="post-nav">
            <div class="post-nav-item">
            </div>
            <div class="post-nav-item">
                <a href="/2020/12/09/npm%E3%80%81nvm%E4%BD%BF%E7%94%A8%E5%9B%BD%E5%86%85%E6%B7%98%E5%AE%9D%E6%BA%90/" rel="next" title="npm、nvm使用国内淘宝源">
                  npm、nvm使用国内淘宝源 <i class="fa fa-chevron-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>







<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      const activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      const commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>
</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">


<div class="copyright">
  &copy; 2020 – 
  <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">yuanzhiying</span>
</div>
<div class="wordcount">
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-chart-line"></i>
    </span>
      <span>站点总字数：</span>
    <span title="站点总字数">16k</span>
  </span>
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
      <span>站点阅读时长 &asymp;</span>
    <span title="站点阅读时长">14 分钟</span>
  </span>
</div>
<div class="busuanzi-count">
    <span class="post-meta-item" id="busuanzi_container_site_uv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-user"></i>
      </span>
      <span class="site-uv" title="总访客量">
        <span id="busuanzi_value_site_uv"></span>
      </span>
    </span>
    <span class="post-meta-item" id="busuanzi_container_site_pv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="site-pv" title="总访问量">
        <span id="busuanzi_value_site_pv"></span>
      </span>
    </span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.js.org/" class="theme-link" rel="noopener" target="_blank">NexT.Gemini</a> 强力驱动
  </div>

    </div>
  </footer>

  
  <script src="//cdn.jsdelivr.net/npm/animejs@3.2.1/lib/anime.min.js"></script>
  <script src="//cdn.jsdelivr.net/npm/@next-theme/pjax@0.4.0/pjax.min.js"></script>
<script src="/js/utils.js"></script><script src="/js/next-boot.js"></script><script src="/js/bookmark.js"></script><script>
var pjax = new Pjax({
  selectors: [
    'head title',
    '.page-configurations',
    '.main-inner',
    '.post-toc-wrap',
    '.languages',
    '.pjax'
  ],
  analytics: false,
  cacheBust: false,
  scrollRestoration: false,
  scrollTo: !CONFIG.bookmark.enable
});

document.addEventListener('pjax:success', () => {
  pjax.executeScripts(document.querySelectorAll('script[data-pjax], .pjax script'));
  NexT.boot.refresh();
  // Define Motion Sequence & Bootstrap Motion.
  if (CONFIG.motion.enable) {
    NexT.motion.integrator
      .init()
      .add(NexT.motion.middleWares.subMenu)
      .add(NexT.motion.middleWares.postList)
      .bootstrap();
  }
  const hasTOC = document.querySelector('.post-toc');
  document.querySelector('.sidebar-inner').classList.toggle('sidebar-nav-active', hasTOC);
  document.querySelector(hasTOC ? '.sidebar-nav-toc' : '.sidebar-nav-overview').click();
  NexT.utils.updateSidebarPosition();
});
</script>


  

<script src="/js/local-search.js"></script>






  
  <script data-pjax async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>




    <div class="pjax">


    </div>
</body>
</html>
